<template>
  <div class="login-view">
    <div class="title">Login From</div>
    <el-form class="from" ref="form" :model="form" label-width="0">
      <el-form-item>
        <el-input v-model="form.name" style="width:350px;" prefix-icon="el-icon-user"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="form.password" show-password style="width:350px;" prefix-icon="el-icon-lock"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login">Login</el-button>
      </el-form-item>
    </el-form>
    <p style="color:#eee">可登录账号：admin1，admin2，admin3，admin4，admin5。</p>
    <p style="color:#eee">密码不限制。</p>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      form: {
        name: 'admin1',
        password: '123456'
      }
    }
  },
  methods: {
    login() {
      /**
       * 这里验证密码的正确性，如果密码正确的话就请求登录
       */
      this.$store.dispatch('user/login', this.form).then(res => {
        // 登录成功后跳转到首页
        this.$router.push({ name: 'Home' })
      }).catch(err => {
        this.$message.error(err);
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.login-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  background-color: #2f3542;
  .title {
    font-size: 40px;
    color: #fff;
  }
  .from {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 25px;
  }
}
</style>
